import serial
import time
import msvcrt

Strgt 	= chr(0x32)
Left 	= chr(0x31)
Right	= chr(0x33)
Stop	= chr(0x34)
RotL 	= chr(0x35)

ser = serial.Serial('COM4', 38400, timeout= 5)
keyboardval = 's'
while keyboardval != 'q' :
	if msvcrt.kbhit() != 0 :
		keyboardval = msvcrt.getch()
		if 	keyboardval == 'w':
			ser.write(Strgt)
			print keyboardval, "0x31"
		if 	keyboardval == 'a':
			ser.write(Left)
			print keyboardval, "0x32"
		if 	keyboardval == 'd':
			ser.write(Right)
			print keyboardval, "0x33"
		if 	keyboardval == 's':
			ser.write(Stop)
			print keyboardval, "0x34"
		if keyboardval == 'z':
			ser.write(RotL)
			print keyboardval, "0x35"
		time.sleep(0.5)
		ser.write(Stop)
			
ser.close()			
print "End of program"